//
//  YKTopWindow.m
//  baisi
//
//  Created by 吴高烽 on 2016/10/25.
//  Copyright © 2016年 吴高烽. All rights reserved.
//

#import "YKTopWindow.h"
@implementation YKTopWindow
static UIWindow *window_ ;//全局变量

+(void)show{
    window_.hidden = NO ;
}
+(void)hidden{
    window_.hidden = YES ;
}
+ (void)initialize{
    window_ = [[UIWindow alloc]init];
    window_.frame = CGRectMake(0, 0, SCWidth, 20);
    window_.windowLevel = UIWindowLevelAlert ;
//    UIView *view = [[UIView alloc]initWithFrame:window_.bounds];
    window_.rootViewController = [[UIViewController alloc]init];
    window_.backgroundColor = [UIColor redColor];
    [window_ addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(windowClick)]];

}
+(void)windowClick{
    UIWindow *window = [UIApplication sharedApplication].keyWindow ;
    [self searchScrollViewInView:window];
}
+(void)searchScrollViewInView:(UIView*)supreView{
    for (UIScrollView *subview in supreView.subviews) {
        if ([subview isKindOfClass:[UIScrollView class]] && [subview isShowOnKeyWindow]) {
            CGPoint offset = subview.contentOffset ;
//            YKLog(@"%.2f--%.2f",offset.y,subview.contentInset.top);
            offset.y = - subview.contentInset.top ;
            [subview setContentOffset:offset];
        }
//        继续查找子控件 （递归的思想）
        [self searchScrollViewInView:subview];
        
    }
}
@end
